<?php
	// SimNet is a Second Life(tm) sim mangement tool that was designed for Fermi Sandbox
    // Copyright (C) 2011 Arthur Fermi
	// 
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License.
	// 
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
	//
	// To receive a copy of this license please visit http://www.gnu.org/licenses/
	
	// URL Format
	// http://<website>/simnet/simnet_eventhistory.php?Request=<Person Requesting>

	// You should not need to edit anything below this line.
	// Get Datbase Settings
	include 'simnet_dbconfig.php';
	
	//Set Variables
	$Who = $_GET['Request'];
		
	// Connect to database
	$con = mysql_connect($Server, $UserName, $Password) or die("Could not connect to the server.  Error: " . mysql_error());
	mysql_select_db($database, $con) or die("Could not connect to the database.  Error: " . mysql_error());

        echo "<h1>SimNet Event History</h1>";
	
	// Get the requesters last 10 events
		echo "<h2>------ Your last 10 event entries ------</h2>" . PHP_EOL;
		$result = mysql_query("SELECT * FROM tblSimNet_Events WHERE tblEvent_Staff LIKE '$Who' ORDER BY tblEvent_Time DESC LIMIT 0, 10") or die(mysql_error());
		$row = mysql_fetch_array($result);
		
		// reset the result resource
		mysql_data_seek($result, 0);


		// Display the information
		echo "<table width=95% border=thin>";
		while ($row = mysql_fetch_array($result)) 
		{
			echo "<tr><td>" . $row['tblEvent_Time'] . "</td>";
			echo "<td>" . $row['tblEvent_Who']  . "</td>";
			echo "<td>" . $row['tblEvent_Type'] . "</td>";
			echo "<td>" . $row['tblEvent_Sim'] . "</td>";
			echo "<td>" . $row['tblEvent_Reason'] . "</td>";
			echo "<td>" . $row['tblEvent_BanLen'] . "</td>";
			echo "<td>" . $row['tblEvent_Comment'] . "</td></tr>";
		}
		echo "</table>";

	// Get the last 100 events
		echo "<h2>------ Last 100 Events ------</h2>" . PHP_EOL;
		$result = mysql_query("SELECT * FROM tblSimNet_Events ORDER BY tblEvent_Time DESC LIMIT 0, 100") or die(mysql_error());
		$row = mysql_fetch_array($result);

		// reset the result resource
		mysql_data_seek($result, 0);

		// Display the information
		echo "<table width=95% border=thin>";
		while ($row = mysql_fetch_array($result)) 
		{
			echo "<tr><td>" . $row['tblEvent_Time'] . "</td>";
			echo "<td>" . $row['tblEvent_Who']  . "</td>";
			echo "<td>" . $row['tblEvent_Type'] . "</td>";
			echo "<td>" . $row['tblEvent_Sim'] . "</td>";
			echo "<td>" . $row['tblEvent_Reason'] . "</td>";
			echo "<td>" . $row['tblEvent_BanLen'] . "</td>";
			echo "<td>" . $row['tblEvent_Comment'] . "</td></tr>";
		}
		echo "</table>";

	mysql_close($con);
?>